﻿using CSharpDay17__API_with_Angular_.Adapters.Data_Adapters;
using CSharpDay17__API_with_Angular_.Adapters.Interfaces;
using CSharpDay17__API_with_Angular_.Data.Model;
using CSharpDay17__API_with_Angular_.Models;
using Microsoft.AspNet.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace CSharpDay17__API_with_Angular_.Controllers
{
    public class apiNotesController : ApiController
    {
        private INoteAdapter _adapter;

        public apiNotesController()
        {
            _adapter = new NoteAdapter();
        }

        public apiNotesController(INoteAdapter a)
        {
            _adapter = a;
        }

        [Authorize]
        public IHttpActionResult Get()
        {
            string userId = User.Identity.GetUserId();
            if (userId == null) return BadRequest("Could not find user");
            List<NoteViewModel> notes = _adapter.GetUserNotes(userId);
            return Ok(notes);
        }
    }
}